package com.example.internetplus.controller;


import com.example.internetplus.accelerationService.StressstService;
import com.example.internetplus.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

import static com.example.internetplus.constrants.ExceptionConstants.*;

@Api("压力测试接口")
@RestController
@RequestMapping("/acceleration")
public class StressController {
    @Autowired
    private StressstService stressstService;
    @ApiOperation("上传execl接口")
    @PostMapping("/readExecl")
    public Result uploadExecl(@ApiParam("execl") MultipartFile uploadExecl){
        try {
            return stressstService.execlRead(uploadExecl.getInputStream());
        } catch (IOException e) {
            return Result.defeat("IO异常",BUISNESS_UPLOAD);
        }
    }
    @ApiOperation("自动读取文件接口")
    @PostMapping("/auto")
    public Result autoRead(){
        return stressstService.autoReadExecl();
    }

    @ApiOperation("查询所有表数据接口")
    @GetMapping("/queryData")
    public Result queryData(){
        return stressstService.queryAll();
    }
}
